//
//  DHSubscriptionController.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/6/8.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHSubscriptionController.h"
#import "DHHomeHotBrandsCell.h"
#import "DHSubscription_CategoryView.h"
#import "DHSubscription_BrandView.h"
#import "DHSubscription_FollowView.h"

@interface DHSubscriptionController ()

@property (weak, nonatomic) IBOutlet UIButton *brandButton;
@property (weak, nonatomic) IBOutlet UIButton *followButton;
@property (weak, nonatomic) IBOutlet UIButton *categoryButton;
@property (weak, nonatomic) IBOutlet UIView *tabView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tabViewWidthLayout;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tabViewLeftLayout;
@property (weak, nonatomic) IBOutlet UIView *topView;

@property (strong, nonatomic) DHSubscription_CategoryView *categoryView;
@property (strong, nonatomic) DHSubscription_BrandView *brandView;
@property (strong, nonatomic) DHSubscription_FollowView *followView;

@end

@implementation DHSubscriptionController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    NSString *change_to_brand_home = [[NSUserDefaults standardUserDefaults] objectForKey:@"change_to_brand_home"];
    if ([change_to_brand_home isEqualToString:@"1"]) {
        [self tabAction:self.brandButton];
        [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:@"change_to_brand_home"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationView setTitleWithString:@"类别"];
    
    self.tabView.layer.cornerRadius = self.tabView.height / 2;
    self.tabViewWidthLayout.constant = (kScreenWidth / 3) / 2;
    self.tabViewLeftLayout.constant = (kScreenWidth / 3) / 4;
    
    CGFloat space = 0;
    if (iPhoneX) {
        space = 23;
    }
    
    self.categoryView = [DHSubscription_CategoryView shareDHSubscription_CategoryView];
    self.categoryView.frame = CGRectMake(0, self.topView.bottom + space, self.view.width, self.view.height - self.navigationView.height - 38 - self.tabBarController.tabBar.height);

    self.brandView = [DHSubscription_BrandView shareDHSubscription_BrandView];
    self.brandView.frame = CGRectMake(0, self.topView.bottom + space, self.view.width, self.view.height - self.navigationView.height - 38 - self.tabBarController.tabBar.height);
    self.followView = [DHSubscription_FollowView shareDHSubscription_FollowView];
    self.followView.frame = CGRectMake(0, self.topView.bottom + space, self.view.width, self.view.height - self.navigationView.height - 38 - self.tabBarController.tabBar.height);
    [self.view addSubview:self.categoryView];
    [self.view addSubview:self.brandView];
    [self.view addSubview:self.followView];
    
    self.brandView.hidden = YES;
    self.followView.hidden = YES;
    [self.categoryView loadData];
}

- (void)dealloc{

}

- (IBAction)tabAction:(id)sender {
    UIButton *button = (UIButton *)sender;
    self.tabViewLeftLayout.constant = button.centerX - button.width / 4;
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    switch (button.tag) {
        case 1000:{
            [self.brandButton setTitleColor:[UIColor colorWithHexString:@"#575757"] forState:UIControlStateNormal];
            [self.followButton setTitleColor:[UIColor colorWithHexString:@"#575757"] forState:UIControlStateNormal];
            self.categoryView.hidden = NO;
            self.brandView.hidden = YES;
            self.followView.hidden = YES;
            [self.categoryView loadData];
            break;
        }
        case 1001:{
            [self.categoryButton setTitleColor:[UIColor colorWithHexString:@"#575757"] forState:UIControlStateNormal];
            [self.followButton setTitleColor:[UIColor colorWithHexString:@"#575757"] forState:UIControlStateNormal];
            self.categoryView.hidden = YES;
            self.brandView.hidden = NO;
            self.followView.hidden = YES;
            [self.brandView loadData];
            break;
        }
        case 1002:{
            [self.brandButton setTitleColor:[UIColor colorWithHexString:@"#575757"] forState:UIControlStateNormal];
            [self.categoryButton setTitleColor:[UIColor colorWithHexString:@"#575757"] forState:UIControlStateNormal];
            self.categoryView.hidden = YES;
            self.brandView.hidden = YES;
            self.followView.hidden = NO;
            [self.followView loadData];
            break;
        }
            
        default:
            break;
    }
}

- (void)routerEventWithName:(NSString *)eventName userInfo:(NSDictionary *)userInfo{
    if ([eventName isEqualToString:@"change_to_brand"]) {
        [self tabAction:self.brandButton];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
